package com.zretc.common.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.Getter;

@Getter
@Data
public class Pager {
    private Integer recordCount;//总记录数
    private Integer pageNum;//当前页码
    private Integer pageSize;//每页显示数量
    private Integer pageCount;//共几页
    private Integer startIndex;//limit起始下标

    public Pager(Integer recordCount, Integer pageNum, Integer pageSize) {
        this.recordCount = recordCount;//1201
        this.pageNum = pageNum;//
        this.pageSize = pageSize;//100
        init();
    }
    public void init(){
        this.pageCount = recordCount / pageSize;
        if(recordCount % pageSize != 0)
            pageCount ++;

        if(pageNum <= 0)
            pageNum = 1;
        if(pageNum > pageCount)
            pageNum = pageCount;

        startIndex = (pageNum - 1) * pageSize;

    }
    @JsonCreator
    public Pager(@JsonProperty("recordCount") int recordCount,
                 @JsonProperty("pageNum") int pageNum,
                 @JsonProperty("pageSize") int pageSize,
                 @JsonProperty("pageCount") int pageCount,
                 @JsonProperty("startIndex") int startIndex) {
        this.recordCount = recordCount;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.pageCount = pageCount;
        this.startIndex = startIndex;
    }
}
